home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 13 - 1997 (partial) / 13.04 Apr 97 / OpenDocExtentions / SelectPart / OSAPlugIn / OSAPlugIn.cpp < prev    next >
Encoding:
Text File  |  1996-06-19  |  3.7 KB  |  179 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.     File:        OSAPlugIn.cpp
  3.     
  4.     Contains:    OSAPlugIn class implementation
  5.     
  6.     Written by:    Sue Dumont
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. ------------------------------------------------------------------------------*/
  10.  
  11. // -- Compiler/Preprocessor Notification --
  12.  
  13. #ifndef _COMPILERDEFS_
  14. #include "CompDefs.h"
  15. #endif
  16.  
  17. // -- OpenDoc Utilities --
  18.  
  19. #ifndef _EXCEPT_
  20. // Exceptions define several important macros (eg. CHECKENV)
  21. // which are used in the SOM method dispatch glue. If Except.h
  22. // is not included early enough, exceptions may not be thrown
  23. // correctly when returning from a SOM method with the "ev" parameter set.
  24. #include <Except.h>
  25. #endif
  26.  
  27. // -- OSAPlugIn Includes --
  28.  
  29. #ifndef SOM_Sample_SelectPartAgent_xh
  30. #include "SelectPartAgent.xh"
  31. #endif
  32.  
  33. #ifndef _OSAPLUGINDEF_
  34. #include "OSAPlugInDef.h"
  35. #endif
  36.  
  37. // -- OpenDoc Includes --
  38.  
  39. #ifndef _ODTYPES_
  40. #include <ODTypes.h>
  41. #endif
  42.  
  43. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  44. #include <StdTypes.xh>
  45. #endif
  46.  
  47. #ifndef _SHPLUGIN_
  48. #include <ShPlugIn.h>
  49. #endif
  50.  
  51. #ifndef SOM_M_ODObject_xh
  52. #include <ODObject.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODObjectNameSpace_xh
  56. #include <ObjectNS.xh>
  57. #endif
  58.  
  59. #ifndef SOM_ODNameSpaceManager_xh
  60. #include <NmSpcMg.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODDraft_xh
  64. #include <Draft.xh>
  65. #endif
  66.  
  67. #ifndef SOM_ODDocument_xh
  68. #include <Document.xh>
  69. #endif
  70.  
  71. #ifndef SOM_ODContainer_xh
  72. #include <ODCtr.xh>
  73. #endif
  74.  
  75. #ifndef SOM_ODStorageSystem_xh
  76. #include <ODStor.xh>
  77. #endif
  78.  
  79. #ifndef SOM_ODStorageUnit_xh
  80. #include <StorageU.xh>
  81. #endif
  82.  
  83. #ifndef SOM_ODSession_xh
  84. #include <ODSessn.xh>
  85. #endif
  86.  
  87. // -- OpenDoc Utilities --
  88.  
  89. #ifndef _ODNEW_
  90. #include <ODNew.h>
  91. #endif
  92.  
  93. #ifndef _ODNEWOBJ_
  94. #include "ODNewObj.h"
  95. #endif
  96.  
  97. #ifndef _ODUTILS_
  98. #include <ODUtils.h>
  99. #endif
  100.  
  101. // -- Macintosh Includes --
  102.  
  103. #ifndef __APPLESCRIPT__
  104. #include <AppleScript.h>
  105. #endif
  106.  
  107. #ifndef __GESTALT__
  108. #include <Gestalt.h>
  109. #endif
  110.  
  111.  
  112. #ifdef __cplusplus
  113. extern "C" {
  114. #endif
  115.  
  116. // The pragma exports are needed for Symantec projects.
  117. #pragma export on    
  118. OSErr ODShellPlugInInstall( Environment* ev, ODDraft* draft, ODShellPlugInActionCodes* action);
  119. #pragma export off
  120.  
  121. #ifdef __cplusplus
  122. }
  123. #endif
  124.  
  125.  
  126. #pragma segment SelectPartAgent
  127.  
  128. //------------------------------------------------------------------------------
  129. // Method:        Install
  130. //
  131. // Description:    Instantiate the SelectPartAgent object and register it
  132. //                into the Object Name Space.
  133. //------------------------------------------------------------------------------
  134.  
  135. OSErr ODShellPlugInInstall( Environment* ev, ODDraft* draft,
  136.                             ODShellPlugInActionCodes* action )
  137. {
  138.     ODNameSpaceManager*                nameSpMgr;
  139.     ODNameSpace*                    objNameSpace;
  140.     ODSLong                            value;
  141.     Sample_SelectPartAgent*        agent = kODNULL;
  142.     OSErr                            err = noErr;
  143.     
  144.     ODVolatile(agent);
  145.  
  146.     SOM_TRY
  147.         // First check to see if AppleScript is present. Only
  148.         // if it is present do we proceed.
  149.         err = Gestalt(gestaltAppleScriptAttr, &value);
  150.     
  151.         if ( !err && (value & (1<<gestaltAppleScriptPresent)) )
  152.         {
  153.             nameSpMgr = ODGetSession(ev, draft)->GetNameSpaceManager(ev);
  154.         
  155.             objNameSpace = nameSpMgr->HasNameSpace(ev, kOSAScriptingTool);
  156.             
  157.             if ( objNameSpace == kODNULL )
  158.             {
  159.                 objNameSpace = nameSpMgr->CreateNameSpace(ev, kOSAScriptingTool,
  160.                                                 kODNULL, (ODULong)1, kODNSDataTypeODObject);
  161.         
  162.                 // "ODNewObject" is called to create a dynamic object. Otherwise, the
  163.                 // SelectPartAgent object will be unloaded when the client part
  164.                 // is unloaded. As a dynamic object, it will stay around and be
  165.                 // deleted properly by OpenDoc.
  166.                 agent = (Sample_SelectPartAgent*) ODNewObject(kAgentID);
  167.                 
  168.                 ((ODObjectNameSpace*)objNameSpace)->Register(ev, kOSAScriptingTool, agent);
  169.             }
  170.         }        
  171.     
  172.         *action = kODShellPlugInNoAction;    
  173.     SOM_CATCH_ALL
  174.         err = ErrorCode();
  175.     SOM_ENDTRY
  176.     
  177.     return err;
  178. }
  179.